﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;

namespace Hbrs.Soa.Restclient.Serializing
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Generating schema file from typedef.");
            XmlSchemas schemas = SchemaSerializer.WriteSchemaFromType(typeof(TestType));
            for (int i = 0; i < schemas.Count; i++)
            {
                using (TextWriter writer = File.CreateText(@"schema_" + i + ".xsd"))
                {
                    schemas[i].Write(writer);
                    writer.Close();
                }
            }

            Console.WriteLine("Reading schema and generating type code.");
            CodeNamespace ns = SchemaSerializer.ImportSchemasAsClasses("schema_0.xsd", "Some.Namespace");
            CodeDomProvider prov = CodeDomProvider.CreateProvider("CSharp");
            using (TextWriter writer = File.CreateText(@"Class.cs"))
            {
                prov.GenerateCodeFromNamespace(ns, writer, null);
                writer.Close();
            }

            Console.WriteLine("Finish");
            Console.ReadLine();

        }
    }
}
